package com.nchu.commondevelopmentframework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nchu.commondevelopmentframework.entity.RoleMenu;
import com.nchu.commondevelopmentframework.mapper.RoleMenuMapper;
import com.nchu.commondevelopmentframework.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @className: RoleMenuServiceImpl
 * @description: 角色菜单实体Service实现类
 * @author: Li Chuanwei
 * @date: 2024/02/23 23:24
 * @Company: Copyright [日期] by [作者或个人]
 **/
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService<RoleMenu> {
    @Autowired
    private RoleMenuMapper roleMenuMapper;
    /**
     * 根据用户ID查询菜单
     *
     * @param roleId 角色Id
     * @param menuId 菜单Id
     * @return boolean值
     */
    @Override
    public Boolean isRoleMenuExist(Long roleId, Long menuId) {
        // 构建查询条件
        QueryWrapper<RoleMenu> queryWrapper = Wrappers.query();
        queryWrapper.eq("menu_id", menuId);
        queryWrapper.eq("role_id", roleId);

        // 执行查询操作
        RoleMenu roleMenu = roleMenuMapper.selectOne(queryWrapper);

        // 判断查询结果是否为空
        return roleMenu != null;
    }

    /**
     * 根据用户ID查询菜单
     *
     * @param roleMenu 实体类
     * @return boolean值
     */
    @Override
    public Boolean removeOne(RoleMenu roleMenu) {
        QueryWrapper<RoleMenu> queryWrapper = Wrappers.query();
        queryWrapper.eq("menu_id", roleMenu.getMenuId());
        queryWrapper.eq("role_id", roleMenu.getRoleId());

        return remove(queryWrapper);
    }
}
